<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection" />
<meta content="emai=no" name="format-detection" />
<link rel="stylesheet" type="text/css" href="/wc/css/common.css" />
<link rel="stylesheet" type="text/css" href="/wc/css/form.css" />
<script type="text/javascript" src="/wc/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="/wc/js/underscore.js"></script>
<script type="text/javascript" src="/wc/js/pinchzoom.js"></script>
<title>芝士妈妈在线</title>
<script type="text/javascript">
		(function (m, ei, q, i, a, j, s) {
			m[a] = m[a] || function () {
				(m[a].a = m[a].a || []).push(arguments)
			};
			j = ei.createElement(q),
				s = ei.getElementsByTagName(q)[0];
			j.async = true;
			j.charset = 'UTF-8';
			j.src = i + '?v=' + new Date().getUTCDate();
			s.parentNode.insertBefore(j, s);
		})(window, document, 'script', '//static.meiqia.com/dist/meiqia.js', '_MEIQIA');
		_MEIQIA('entId', '20405');
		_MEIQIA('withoutBtn');
		_MEIQIA('init');
	</script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
	//调用微信JS api 支付
	function jsApiCall()
	{
		var id = "<?php echo $id;?>";
		var bookingId = "<?php echo $booking_id?>";
		
		WeixinJSBridge.invoke(
			'getBrandWCPayRequest',
			<?php echo $jsApiParameters; ?>,
			function(res){
				WeixinJSBridge.log(res.err_msg);
				if(res.err_msg == 'get_brand_wcpay_request:ok')
				{
					alert("支付成功");
					$.ajax({
						url: "/wxpay/changestatus",
						type: "post",
						data: {id: id, booking_id: bookingId},
						success: function(msg){
							window.location.href = "/wxpay/success?id="+id + "&booking_id=" + bookingId; 
						},
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							  // 通常情况下textStatus和errorThown只有其中一个有值 
							  this; // the options for this ajax request
						}
					});
				}
				else if(res.err_msg == 'get_brand_wcpay_request:cancel')
				{
					window.history.back();
				}
			}
		);
	}

	function callpay(id, bookingId)
	{
		//ajax提交数据保存

		if (typeof WeixinJSBridge == "undefined"){
		    if( document.addEventListener ){
		        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
		    }else if (document.attachEvent){
		        document.attachEvent('WeixinJSBridgeReady', jsApiCall);
		        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
		    }
		}else{
		    jsApiCall();
		}
	}

	</script>


</head>
<body>
	<script>
        $(document).ready(function(){
		callpay();

        });

    </script>
</body>
</html>
